/************************************************************
 * Project Name         [Thinking_In_Java]
 * File Name            [Example_10_Traffic_Lamp.java]
 * Creation Date        [20-Jun-2014]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ************************************************************/
package pkg_02_oop;

/**
 * 枚举
 * 
 * @author 不落的太阳(Sean Yang)
 * @version 1.0
 * @since JDK 6
 * 
 */
public class Example_10_Traffic_Lamp {

	/**
	 * 测试方法
	 * 
	 * @param args
	 *            命令行参数
	 */
	public static void main(String[] args) {
		TrafficLamp.RED.nextLamp();
		TrafficLamp.GREEN.nextLamp();
		TrafficLamp.YELLOW.nextLamp();
	}

}

/**
 * 枚举类型 - 交通灯
 * 
 * @author 不落的太阳(Sean Yang)
 * @version 1.0
 * @since JDK 6
 */
enum TrafficLamp {

	RED(30) {
		@Override
		public TrafficLamp nextLamp() {
			System.out.println("Next 30 seconds ---> Green");
			return GREEN;
		}
	},
	GREEN(45) {
		@Override
		public TrafficLamp nextLamp() {
			System.out.println("Next 45 seconds ---> Yellow");
			return YELLOW;
		}
	},
	YELLOW(15) {
		@Override
		public TrafficLamp nextLamp() {
			System.out.println("Next 15 seconds ---> Red");
			return RED;
		}
	};

	// 枚举的构造方法不能声明为public的
	private TrafficLamp(int time) {
		this.time = time;
	}

	private int time;

	/**
	 * 抽象方法
	 * 
	 * @return 下一个交通信号
	 */
	public abstract TrafficLamp nextLamp();

	/**
	 * 交通信号切换的间隔时间
	 * 
	 * @return 间隔时间
	 */
	public int getTime() {
		return time;
	}
}
